package com.example.huangyuanquan

import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView

class MainActivity : AppCompatActivity() {
    private lateinit var recyclerView: RecyclerView
    private var studentList: MutableList<Student> = ArrayList()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        title = "hyq2022180410" // Replace with your name and student ID

        recyclerView = findViewById(R.id.student_list).apply {
            layoutManager = LinearLayoutManager(this@MainActivity)
        }

        findViewById<View>(R.id.add_student_button).setOnClickListener {
            val intent = Intent(this@MainActivity, AddStudentActivity::class.java)
            startActivityForResult(intent, REQUEST_CODE_ADD_STUDENT)
        }
    }
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == REQUEST_CODE_ADD_STUDENT && resultCode == RESULT_OK) {
            val newStudent = data?.getParcelableExtra<Student>("new_student")
            newStudent?.let {
                studentList.add(it)
                saveStudents()
            }
        }
    }

    private fun loadStudents(): MutableList<Student> {
        // Load students from SharedPreferences or database
        return ArrayList() // Return an empty list for now
    }

    private fun saveStudents() {
        // Save students to SharedPreferences or database
    }

    companion object {
        private const val REQUEST_CODE_ADD_STUDENT = 1
        private const val STUDENT_DATA = "student_data"
    }
}